/* eslint-disable */
import Vue from 'vue'

const _error = console.error;
console.error = function (...args) {
  console.info('异常信息')
  console.info(args)
  global.utils.logError('通用异常',args)
  _error.call(
    console,
    '异常:' + [].slice.call(args).join('  '),
  );
}

// 默认抛出错误
Vue.config.errorHandler = function(err, vm) {
  console.error('Vue.config.errorHandler.异常如下\n');
  console.error(err);
  console.error('Vue.config.errorHandler.组件如下\n');
  console.error(vm);
}

Vue.config.warnHandler = function(msg, vm, trace) {
  console.warn('Vue.config.warnHandler.警告如下\n');
  console.warn(msg);
  console.warn('Vue.config.warnHandler.组件如下\n');
  console.warn(vm);
  console.warn('Vue.config.warnHandler.堆栈如下\n');
  console.warn(trace);
}

// 导入elementUI组件
import ElementUI from 'element-ui'
import 'default-passive-events' // 解决浏览器passive警告
Vue.use(ElementUI, {
  size: 'small',
  zIndex: 3000
})

import VueCookies from 'vue-cookies'
Vue.use(VueCookies)
global.$cookies = Vue.prototype.$cookies

// 导入svg-icon
import "babel-polyfill"
import 'element-ui/lib/theme-chalk/index.css'
// 样式配置
import './assets/css/main.scss'
// 导入全局样式
import '@/styles/index.scss'


// 导入路由
import router from './router/index'

// 导入vuex
import store from './vuex/index'

// 导入ajax工具,并挂载到全局VUE上
import Ajax from './util/ajax'

Vue.prototype.$ajax = Ajax

// 导入根组件
import App from './App.vue'

// 将定制化配置和工具类挂载到global上面
import {
  moduleMap
} from './settings.js'
import utils from './util/utils.js'

import strings from './util/strings.js'
import utilNum from './util/utilNum.js'
import dates from './util/dates.js'
import pyutils from './util/pyutils.js'
import queryWrappers from './util/queryWrappers.js'
import utilVue from './util/utilVue.js'
import utilMessage from './util/utilMessage.js'
import settings from './settings.js'
import constCommon from './util/const/constCommon.js'

import _ from 'lodash'
import 'jquery'

import VueParticles from 'vue-particles'
Vue.use(VueParticles)

// 导入VantUI组件
import Vant from 'vant';
import 'vant/lib/index.css'
Vue.use(Vant)

global.moduleMap = moduleMap
global.$ajax = Ajax
global.utils = Vue.prototype.utils = utils
global.dates = Vue.prototype.dates = dates
global.strings = Vue.prototype.strings = strings
global.utilNum = Vue.prototype.utilNum = utilNum
global.pyutils = Vue.prototype.pyutils = pyutils
global.queryWrappers = Vue.prototype.queryWrappers = queryWrappers
global.$newWrapper = Vue.prototype.$newWrapper = queryWrappers.newWrapper
global.utilVue = Vue.prototype.utilVue = utilVue
global.utilMessage = Vue.prototype.utilMessage = utilMessage
global.settings = Vue.prototype.settings = settings
global.constCommon = Vue.prototype.constCommon = constCommon
global._ = Vue.prototype._ = _
Vue.config.productionTip = false
import customAnchor from '@/components/custom/form/customAnchor.vue'

Vue.component('customAnchor', customAnchor)

//国际化
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)

const i18n = new VueI18n({
  locale: 'zh', // 定义默认语言为中文 
  messages: {
    'zh': require('@/assets/lang/zh.js'),
    'en': require('@/assets/lang/en.js'),
    'ja': require('@/assets/lang/ja.js')
  },
  silentTranslationWarn: true
});

//自定义组件开始
// 引入TDesign
import TDesign from 'tdesign-vue';
// 引入TDesign组件库的少量全局样式变量
import 'tdesign-vue/es/style/index.css';
Vue.use(TDesign);

//输入框
import DataList from '@/components/app/DataList.vue'
Vue.component('DataList', DataList)

//输入框
import customInput from '@/components/custom/form/customInput'
Vue.component('customInput', customInput)

//文本域
import customTextarea from '@/components/custom/form/customTextarea'
Vue.component('customTextarea', customTextarea)

//数字框
import customInputNumber from '@/components/custom/form/customInputNumber'
Vue.component('customInputNumber', customInputNumber)

//开关
import customSwitch from '@/components/custom/form/customSwitch'
Vue.component('customSwitch', customSwitch)

//复选框
import customCheckbox from '@/components/custom/form/customCheckbox'
Vue.component('customCheckbox', customCheckbox)

//单选框
import customRadio from '@/components/custom/form/customRadio'
Vue.component('customRadio', customRadio)

//下拉框
import customSelect from '@/components/custom/form/customSelect'
Vue.component('customSelect', customSelect)

//按钮
import customButton from '@/components/custom/form/customButton'
Vue.component('customButton', customButton)

//树组件
import customTree from '@/components/custom/form/customTree'
Vue.component('customTree', customTree)

//间距组件
import customSpace from '@/components/custom/form/customSpace'
Vue.component('customSpace', customSpace)

//抽屉组件
import customDrawer from '@/components/custom/form/customDrawer'
Vue.component('customDrawer', customDrawer)

//表格弹框选择
import tableDrawer from '@/components/custom/bus/tableDrawer'
Vue.component('tableDrawer', tableDrawer)

//表单
import customForm from '@/components/custom/form/customForm'
Vue.component('customForm', customForm)

//表单项
import customFormItem from '@/components/custom/form/customFormItem'
Vue.component('customFormItem', customFormItem)

//日期组件
import customDatePicker from '@/components/custom/form/customDatePicker'
Vue.component('customDatePicker', customDatePicker)

//日期组件 区间
import customDatePickerRange from '@/components/custom/form/customDatePickerRange'
Vue.component('customDatePickerRange', customDatePickerRange)

//对话框
import customDialog from '@/components/custom/form/customDialog'
Vue.component('customDialog', customDialog)

//对话框
import customTooltip from '@/components/custom/form/customTooltip'
Vue.component('customTooltip', customTooltip)
//对话框
import customEmpty from '@/components/custom/form/customEmpty'
Vue.component('customEmpty', customEmpty)
//自定义组件结束

const vue = new Vue({
  render: h => h(App),
  store,
  router,
  i18n,
  mounted () {
    try {
      document.title = global.settings.resources.appTitle
    }catch (e) {
      console.error(e)
    }

    // 禁止回退
    window.onpopstate = () => {
      let allowBack = localStorage.getItem('allowBack')
      // 不允许回退
      if (false == allowBack) {
        history.go(1)
      }
    }
  }
}).$mount('#root')
global.vue = vue
export default vue
